package org.example.批量消息.消费;

import lombok.SneakyThrows;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

/**
 * @Auther:Liu
 * @Testname:批量消息消费
 * @Date:2025/8/22 18:56
 */
public class 批量消息消费 {
    @SneakyThrows
    public static void main(String[] args) {
        DefaultMQProducer producer = new DefaultMQProducer("producer_group_b");
        producer.setNamesrvAddr("124.220.170.254:9876");
        producer.start();
        List<Message> messages = new ArrayList<>();
        for (int i = 1; i < 21; i++) {
            String topic = "TopicA";
            String tags = "piliang";
            String body = "Hello,piliang!index:" + i;
            Message message = new Message(topic, tags, body.getBytes(StandardCharsets.UTF_8));
            messages.add(message);
        }
        SendResult sendResult = producer.send(messages);
        System.out.println(sendResult);
        producer.shutdown();
    }
}
